package com.example.mobile2021606185zhn0330;

import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

import androidx.appcompat.app.AppCompatActivity;

public class MainActivity extends AppCompatActivity {

    private TextView tvMainTitle;
    private EditText editTextTextPassword2;
    private EditText editTextTextPassword3;
    private Button button;
    private Button button2;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initView();
        button.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                String editTextPassword2 = editTextTextPassword2.getText().toString();
                String editTextPassword3 = editTextTextPassword3.getText().toString();
                if (editTextPassword2.length() == 0) {
                    Log.d("登录", "请输入用户名: ");
                    Toast.makeText(MainActivity.this, "请输入用户名", Toast.LENGTH_SHORT).show();
                } else if (editTextPassword3.length() == 0) {
                    Log.i("登录", "请输入密码: ");
                    Toast.makeText(MainActivity.this, "请输入密码", Toast.LENGTH_SHORT).show();
                } else {
                    if (editTextPassword2.equals("admin") & editTextPassword3.equals("123456")) {
                        Log.i("登录", "登录成功: ");
                        Toast.makeText(MainActivity.this, "登录成功", Toast.LENGTH_SHORT).show();
                    } else {
                        Log.i("登录", "登录失败: ");
                        Toast.makeText(MainActivity.this, "登录失败", Toast.LENGTH_SHORT).show();
                    }
                }


            }
        });
        initView();
        button2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                editTextTextPassword2.setText(null);
                editTextTextPassword3.setText(null);
            }
        });
    }

    private void initView() {
        tvMainTitle = (TextView) findViewById(R.id.tv_main_title);
        editTextTextPassword2 = (EditText) findViewById(R.id.editTextTextPassword2);
        editTextTextPassword3 = (EditText) findViewById(R.id.editTextTextPassword3);
        button = (Button) findViewById(R.id.button);
        button2 = (Button) findViewById(R.id.button2);
    }
}